package com.buba.springcloud.controller;

import com.buba.springcloud.entities.CommonResult;
import com.buba.springcloud.entities.HfFoods;
import com.buba.springcloud.pojo.Foods;
import com.buba.springcloud.service.OrderFrontDeskService;
import com.buba.springcloud.service.OrderService;
import com.buba.springcloud.util.JwtUtil;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/frontdesk/order")
public class OrderFrontDeskController {
    @Resource
    private OrderFrontDeskService orderFrontDeskService;

    @Resource
    private OrderService orderService;

    @GetMapping("/getOrderByUserId")
    public CommonResult getHforeders(HttpServletRequest request){
        String token = request.getHeader("token");
        Claims claims = JwtUtil.parseJWT(token);
        Integer id = (Integer) claims.get("id");
        CommonResult hforeders = orderFrontDeskService.getHforeders(null, id);
        return hforeders;
    }

//    @PostMapping("/createOrder")
//    public CommonResult createOrder(@RequestBody CreateOrder dingdanInfo , HttpServletRequest request){
//        String token = request.getHeader("token");
//        Claims claims = JwtUtil.parseJWT(token);
//        long id =(long) claims.get("id");
//        Map menuList = dingdanInfo.getMenuList();
//        return null;
//    }

    @PostMapping("/findOrderFoods")
    public CommonResult findOrderFoods(@RequestBody List<Foods> foods) {
        List<HfFoods> foodsList = orderService.findOrderFoods(foods);
        return new CommonResult(200,"查询成功",foodsList);
    }

    @PostMapping("/createOrder")
    public CommonResult createOrder(){


        return new CommonResult(200,"订单创建成功");
    }
}
